/*********************************************************************************
    This software is created under the term GNU General Public License.
    You should have received a copy of the GNU General Public License.
    If not, write to the Free Software Foundation, 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.

critical:
    encapsulation critical section over different OSes

author: xiangyun.kong(lo-sor@hotmail.com)
create: 2-26-2011

changes:

**********************************************************************************/
#ifndef __clib_critical_h__
#define __clib_critical_h__

#ifdef __cplusplus
extern "C"{
#endif

#if defined( _WIN32 ) || defined( _WIN64 )

#include <windows.h>
typedef CRITICAL_SECTION critical;

#elif defined( LINUX )

#include <pthread.h>
typedef pthread_mutex_t critical;

#else

#error os unsupported

#endif // system distinguish

int init_critical( critical *cs );
void enter_critical( critical *cs );
int try_enter_critical( critical *cs );
void leave_critical( critical *cs );
int destroy_critical( critical *cs );

#ifdef __cplusplus
};
#endif

#endif // __clib_critical_h__
